<template>
	<view class="index-container">
		<!-- 地图区域（包含导航栏和悬浮内容） -->
		<view class="map-wrapper">
			<!-- 地图组件 -->
			<map class="map" :latitude="30.287459" :longitude="120.153576" scale="15">
			</map>

			<!-- 导航栏 -->
			<view class="custom-nav" :style="{ paddingTop: statusBarHeight + 'px' }">
				<view class="nav-content">
					<view class="nav-title">
						<text class="title">快马日结</text>
						<text class="subtitle">招工找活 快人一步</text>
					</view>
				</view>
			</view>

			<!-- 公告栏 -->
			<view class="notice-bar" :style="{ top: statusBarHeight + 44 + 'px' }">
				<image src="/static/images/speaker.png" mode="aspectFit" class="audio-icon"></image>
				<text class="notice-text">参考软招包人入，工价225元/分钟招满</text>
			</view>

			<!-- 零工数量提示 -->
			<view class="worker-count">
				<text>附近有1502位零工</text>
			</view>

			<!-- 快马日结卡片和按钮的包裹框 -->
			<view class="quick-publish-wrapper">
				<view class="quick-card">
					<view class="card-info">
						<image src="/static/images/publish-icon.png" mode="aspectFit" class="card-icon"></image>
						<text>快马日结</text>
						<text class="highlight">帮您招聘靠谱的临时工</text>
						<text class="right-arrow">></text>
					</view>
				</view>
				<button class="publish-btn" @click="goToPublish">
					去发布招工
					<text class="btn-tag">首单免费</text>
				</button>
			</view>
		</view>

		<!-- 功能区域 -->
		<view class="function-area">
			<view class="function-nav">
				<view class="nav-item" style="width: 40%;" @click="navigateToLocationManage">
					<view class="tooltip" v-if="showLocationTip">
						指引员工上门
						<text class="close-btn" @click.stop="hideLocationTip">×</text>
					</view>
					<view class="nav-title">招工地址管理</view>
					<view class="nav-subtitle">上传照片视频</view>
					<view class="location-icon">
						<image src="/static/images/location-pin.png" mode="aspectFit"></image>
					</view>
				</view>

				<view class="nav-item" @click="navigateToHelp">
					<view class="nav-icon">
						<image src="/static/images/my/function3.png" mode="aspectFit"></image>
					</view>
					<view class="nav-title">遇到问题</view>
				</view>

				<view class="nav-item" @click="contactCustomerService">
					<view class="nav-icon">
						<image src="/static/images/my/service2.png" mode="aspectFit"></image>
					</view>
					<view class="nav-title">联系客服</view>
				</view>
			</view>
			<view class="service-cards">
				<view class="left-card" @click="goToWorkPlatform">
					<text class="card-title">专业零工平台</text>
					<text class="card-subtitle">快速接活 及时结算</text>
					<image src="/static/images/tai.png" mode="" class="card-image1"></image>
				</view>
				<view class="right-cards">
					<view class="right-card" @click="goToServiceAcceleration">
						<view class="card-content">
							<text class="card-title">招工加速服务</text>
							<text class="card-subtitle">加专属招工管家</text>
							<view class="card-btn">去领取</view>
						</view>
						<image src="/static/images/zhao1.png" mode="aspectFit" class="card-image"></image>
					</view>
					<view class="right-card" @click="goToTutorial">
						<view class="card-content">
							<text class="card-title">下单教程</text>
							<text class="card-subtitle">帮你快速上手</text>
							<view class="card-btn">去观看</view>
						</view>
						<image src="/static/images/xia.png" mode="aspectFit" class="card-image"></image>
					</view>
				</view>
			</view>

			<view class="service-list">
				<!-- 旧的列表样式，现在隐藏 -->
			</view>
		</view>

		<!-- 功能导航区域 -->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0,
				showLocationTip: true,
			}
		},
		methods: {
			hideLocationTip(e) {
				// 阻止事件冒泡，防止触发父元素的点击事件
				e.stopPropagation();
				this.showLocationTip = false;
				// 保存状态到本地存储，下次不再显示
				uni.setStorageSync('locationTipShown', true);
			},
			goToPublish() {
				uni.navigateTo({
					url: '/pages/publish/publish'
				})
			},
			goToWorkPlatform() {
				uni.showToast({
					title: '专业零工平台功能即将上线',
					icon: 'none'
				})
			},
			goToServiceAcceleration() {
				uni.showToast({
					title: '招工加速服务功能即将上线',
					icon: 'none'
				})
			},
			goToTutorial() {
				uni.showToast({
					title: '下单教程功能即将上线',
					icon: 'none'
				})
			},
			// 功能导航方法
			navigateToLocationManage() {
				uni.navigateTo({
					url: '/pages/location/manage'
				});
			},

			navigateToHelp() {
				uni.navigateTo({
					url: '/pages/help/index'
				});
			},

			contactCustomerService() {
				// 打开客服会话
				if (uni.openCustomerServiceChat) {
					uni.openCustomerServiceChat({
						extInfo: {
							url: '您的客服URL'
						},
						corpId: '您的企业ID',
						success(res) {
							console.log('打开客服会话成功');
						},
						fail(err) {
							console.error('打开客服会话失败', err);
							// 备用方案：拨打客服电话
							uni.showModal({
								title: '联系客服',
								content: '是否拨打客服电话？',
								success: (res) => {
									if (res.confirm) {
										uni.makePhoneCall({
											phoneNumber: '您的客服电话'
										});
									}
								}
							});
						}
					});
				} else {
					// 如果平台不支持openCustomerServiceChat
					uni.showModal({
						title: '联系客服',
						content: '是否拨打客服电话？',
						success: (res) => {
							if (res.confirm) {
								uni.makePhoneCall({
									phoneNumber: '您的客服电话'
								});
							}
						}
					});
				}
			}
		},
		onLoad() {
			const systemInfo = uni.getSystemInfoSync()
			this.statusBarHeight = systemInfo.statusBarHeight

			// 默认显示提示，除非已经显示过
			// const tipShown = uni.getStorageSync('locationTipShown')
			// this.showLocationTip = tipShown ? false : true
			console.log('是否显示位置提示:', this.showLocationTip)

			uni.getLocation({
				type: 'gcj02',
				success: function(res) {
					console.log('当前位置：', res)
				}
			})
		}
	}
</script>

<style lang="scss">
	.index-container {
		min-height: 100vh;
		background: #f8f8f8;
	}

	.map-wrapper {
		position: relative;
		height: 60vh;

		.map {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			z-index: 1;
		}
	}

	.custom-nav {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		z-index: 2;
		background: transparent;

		.nav-content {
			height: 44px;
			display: flex;
			align-items: center;
			padding: 0 15px;

			.nav-title {
				display: flex;
				align-items: center;

				.title {
					font-size: 18px;
					font-weight: bold;
					color: #333;
				}

				.subtitle {
					font-size: 12px;
					color: #666;
					margin-left: 8px;
				}
			}
		}
	}

	.notice-bar {
		position: absolute;
		left: 15px;
		right: 15px;
		z-index: 2;
		background: rgba(255, 255, 255, 0.8);
		border-radius: 20px;
		padding: 6px 12px;
		display: flex;
		align-items: center;
		backdrop-filter: blur(5px);

		.audio-icon {
			width: 16px;
			height: 16px;
			margin-right: 8px;
			opacity: 0.8;
		}

		.notice-text {
			font-size: 12px;
			color: #07C160;
			flex: 1;
		}
	}

	.worker-count {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		z-index: 2;
		background: rgba(0, 0, 0, 0.6);
		color: #fff;
		padding: 6px 16px;
		border-radius: 20px;
		font-size: 14px;
	}

	.quick-publish-wrapper {
		position: absolute;
		left: 15px;
		right: 15px;
		bottom: 20px;
		z-index: 2;
		background: #fff;
		border-radius: 12px;
		padding: 15px;

		.quick-card {
			margin-bottom: 15px;

			.card-info {
				display: flex;
				align-items: center;
				position: relative;

				.card-icon {
					width: 20px;
					height: 20px;
					margin-right: 8px;
				}

				text {
					font-size: 14px;
				}

				.highlight {
					color: #ff6b00;
					margin-left: 8px;
				}

				.right-arrow {
					position: absolute;
					right: 0;
					color: #999;
				}
			}
		}

		.publish-btn {
			width: 100%;
			height: 44px;
			// line-height: 44px;
			background: #FFD000;
			color: #000;
			font-size: 16px;
			border-radius: 20rpx;
			border: none;
			position: relative;
			padding: 0;
			margin: 0;

			&::after {
				border: none;
			}

			.btn-tag {
				position: absolute;
				right: -5px;
				top: -5px;
				background: #FF4B33;
				color: #fff;
				font-size: 12px;
				padding: 0px 8px;
				border-radius: 0px 14px 0px 14px;
				transform: scale(0.9);
			}
		}
	}

	.function-area {
		background: #fff;
		padding: 20px 15px;

		.section-title {
			font-size: 16px;
			font-weight: bold;
			margin-bottom: 20px;
		}

		.quick-actions {
			display: flex;
			flex-wrap: wrap;
			gap: 10px;
			margin-bottom: 30px;

			.action-item {
				flex: 1;
				min-width: calc(50% - 5px);
				background: #F8F9FB;
				border-radius: 12px;
				padding: 15px;
				min-height: 80px;
				position: relative;

				.tooltip {
					position: absolute;
					left: 0;
					top: -36px;
					background: #1485EE;
					color: #fff;
					font-size: 12px;
					padding: 6px 28px 6px 12px;
					border-radius: 4px;
					white-space: nowrap;
					z-index: 10;

					&::after {
						content: '';
						position: absolute;
						bottom: -6px;
						left: 20px;
						width: 0;
						height: 0;
						border-left: 6px solid transparent;
						border-right: 6px solid transparent;
						border-top: 6px solid #1485EE;
					}

					.close-btn {
						position: absolute;
						right: 8px;
						top: 50%;
						transform: translateY(-50%);
						width: 16px;
						height: 16px;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 14px;
						color: rgba(255, 255, 255, 0.8);
					}
				}

				.action-content {
					display: flex;
					flex-direction: column;
					height: 100%;

					.action-title {
						font-size: 16px;
						font-weight: bold;
						color: #333;
						margin-bottom: 4px;
					}

					.action-subtitle {
						font-size: 12px;
						color: #999;
					}

					.action-image {
						width: 80px;
						height: 80px;
						position: absolute;
						right: 10px;
						bottom: 10px;
					}

					.action-tag {
						position: absolute;
						right: 10px;
						top: 10px;
						background: #F5F5F5;
						color: #666;
						font-size: 12px;
						padding: 2px 8px;
						border-radius: 10px;
					}
				}

				&:first-child {
					.tooltip {
						position: absolute;
						left: 0;
						top: -36px;
						background: #1485EE;
						color: #fff;
						font-size: 12px;
						padding: 6px 28px 6px 12px;
						border-radius: 4px;
						white-space: nowrap;
						z-index: 10;

						&::after {
							content: '';
							position: absolute;
							bottom: -6px;
							left: 20px;
							width: 0;
							height: 0;
							border-left: 6px solid transparent;
							border-right: 6px solid transparent;
							border-top: 6px solid #1485EE;
						}

						.close-btn {
							position: absolute;
							right: 8px;
							top: 50%;
							transform: translateY(-50%);
							width: 16px;
							height: 16px;
							display: flex;
							align-items: center;
							justify-content: center;
							font-size: 14px;
							color: rgba(255, 255, 255, 0.8);
						}
					}
				}
			}
		}

		.service-cards {
			display: flex;
			gap: 10px;
			margin-bottom: 20px;

			.left-card {
				flex: 1;
				background: linear-gradient(180deg, #5fadf5, #fff);
				border-radius: 12px;
				padding: 15px;
				position: relative;
				height: 170px;
				color: #fff;
				overflow: hidden;
				display: flex;
				flex-direction: column;
				align-items: center;

				.card-title {
					font-size: 16px;
					font-weight: bold;
					color: #fff;
					display: block;
					position: relative;
					z-index: 2;
				}

				.card-subtitle {
					font-size: 12px;
					color: rgba(255, 255, 255, 0.8);
					margin-top: 4px;
					display: block;
					position: relative;
					z-index: 2;
				}

				.card-image {
					position: absolute;
					right: 0;
					bottom: 0;
					width: 120px;
					height: 120px;
					z-index: 1;
				}
				.card-image1{
					width: 91px;
					height: 76px;
					margin-top: 36px;
					border-radius: 20rpx;
				}

				.card-tag {
					position: absolute;
					right: 10px;
					top: 10px;
					background: rgba(255, 255, 255, 0.2);
					color: #fff;
					font-size: 12px;
					padding: 4px 12px;
					border-radius: 12px;
					z-index: 2;
				}
			}

			.right-cards {
				flex: 1;
				display: flex;
				flex-direction: column;
				gap: 10px;

				.right-card {
					background: #dbeefd !important;
					border-radius: 12px;
					padding: 15px;
					height: 80px;
					position: relative;
					display: flex;
					justify-content: space-between;
					align-items: center;

					&:last-child {
						background: #dbeefd;
					}

					.card-content {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: center;
						height: 100%;

						.card-title {
							font-size: 16px;
							font-weight: bold;
							color: #333;
							display: block;
							margin-bottom: 4px;
						}

						.card-subtitle {
							font-size: 12px;
							color: #999;
							margin-bottom: 10px;
							display: block;
						}

						.card-btn {
							display: inline-block;
							background: #F5F5F5;
							color: #3370FF;
							font-size: 12px;
							padding: 4px 12px;
							border-radius: 12px;
							width: fit-content;
						}
					}

					.card-image {
						width: 60px;
						height: 60px;
						position: absolute;
						right: 5rpx;
						bottom: 5rpx;
					}
				}
			}
		}

		.service-list {
			display: none;
			/* 隐藏旧的列表样式 */
		}
	}

	/* 功能导航样式 */
	.function-nav {
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		background-color: #f8f8f8;
		margin: 20rpx 0;
	}

	.nav-item {
		position: relative;
		width: 28%;
		height: 160rpx;
		background-color: #ffffff;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20rpx;
		box-sizing: border-box;
		box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
	}
	
	.tooltip {
		position: absolute;
		left: 0;
		top: -40rpx;
		background: #333333;
		color: #fff;
		font-size: 24rpx;
		padding: 10rpx 60rpx 10rpx 20rpx;
		border-radius: 8rpx;
		white-space: nowrap;
		z-index: 10;
		
		&::after {
			content: '';
			position: absolute;
			bottom: -10rpx;
			left: 40rpx;
			width: 0;
			height: 0;
			border-left: 10rpx solid transparent;
			border-right: 10rpx solid transparent;
			border-top: 10rpx solid #333333;
		}
		
		.close-btn {
			position: absolute;
			right: 10rpx;
			top: 50%;
			transform: translateY(-50%);
			width: 32rpx;
			height: 32rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: rgba(255, 255, 255, 0.8);
		}
	}

	.nav-title {
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
		margin-bottom: 8rpx;
		text-align: center;
	}

	.nav-subtitle {
		font-size: 22rpx;
		color: #999;
		text-align: center;
	}

	.nav-icon {
		margin-bottom: 10rpx;
	}

	.nav-icon image {
		width: 48rpx;
		height: 48rpx;
	}

	.location-icon {
		position: absolute;
		bottom: 15rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.location-icon image {
		width: 32rpx;
		height: 32rpx;
	}
</style>